<template>
<div>
    <AutoQuery ref="auto-query" :query="query" :page="page" :buttons="['search','search_all','export_excel']"></AutoQuery>
    <Button @click="handleAdd()" style="float:right;" type="primary" :disabled="disabledButton('113311')">添加</Button>
    <AutoTable :columns="columns5" :data="listedCompanyList" :page="page"></AutoTable>
    <Modal v-model="showModal" width="80%">
        <p slot="header" style="color:#f60;text-align:center">
            <Icon type="information-circled"></Icon>
            <span>上市企业详细信息</span><br>
            
        </p>
        <div>
            
            <CompleteListedCompanyPage ref="ref1" :listedCompany="listedCompany" @ListenBoardEvent="listenBoard" :Disabled="!is_modify"></CompleteListedCompanyPage>
        </div>
        <div slot="footer">
            <div style="text-align:center;">
                <Button type="primary" @click="handleSubmit()" v-if="is_modify" :disabled="disabledButton('113311')">提交</Button>
                <Button type="primary" @click="handleChange()" v-if="!is_modify" :disabled="disabledButton('113313')">修改</Button>
                <Button @click="handleCancel()">取消</Button>
            </div>
        </div>
    </Modal>
    <Modal v-model="checkModal" class="sheet" width="900px">
        <p slot="header" style="color:#f60;text-align:center">
            <span>上市信息详情</span>

        </p>
            <table>
                <thead>
                    <tr><th style="width:18%;">审核项</th><th>内容</th></tr>
                </thead>
                <tr><td>企业名称</td><td>{{listedCompany.company_name}}</td></tr>
                <tr><td>注册地址</td><td>{{listedCompany.registerde_address}}</td></tr>
                <tr><td>注册资本</td><td>{{listedCompany.registered_capital}}</td></tr>
                <tr><td>总股本</td><td>{{listedCompany.total_equity}}</td></tr>
                <tr><td>国有股</td><td>{{listedCompany.state_owned_shares}}</td></tr>
                <tr><td>法人股</td><td>{{listedCompany.legal_person_share}}</td></tr>
                <tr><td>自然人股</td><td>{{listedCompany.natural_person_shares}}</td></tr>
                <tr><td>设立时间</td><td>{{getYear(listedCompany.formated_create_time)}}</td></tr>
                <tr><td>控股股东</td><td>{{listedCompany.controlling_shareholder}}</td></tr>
                <tr><td>法人代表</td><td>{{listedCompany.legal_representative}}</td></tr>
                <tr><td>联系人</td><td>{{listedCompany.contact_person}}</td></tr>
                <tr><td>移动电话</td><td>{{listedCompany.mobile_phone}}</td></tr>
                <tr><td>办公电话</td><td>{{listedCompany.office_phone}}</td></tr>
                <tr><td>所属行业</td><td>{{listedCompany.industry_involved}}</td></tr>
                <tr><td>主营业务</td><td>{{listedCompany.main_business}}</td></tr>
                <tr><td>企业性质</td><td>{{listedCompany.enterprise_nature}}</td></tr>
                <tr><td>是否高新技术企业</td><td>{{listedCompany.high_tech_enterprise}}</td></tr>
                <tr><td>是否贫困县</td><td>{{listedCompany.poverty_level}}</td></tr>
                <tr><td>是否省级扶贫龙头企业</td><td>{{listedCompany.Anti_poverty_leading_enterprise}}</td></tr>
                <tr><td>改制时间</td><td>{{getYear(listedCompany.formated_restructurt_time)}}</td></tr>
                <tr><td>股份公司设立形式</td><td>{{listedCompany.corporation_set_up_form}}</td></tr>
                <tr><td>辅导机构</td><td>{{listedCompany.counselling_organization}}</td></tr>
                <tr><td>保荐机构（人）</td><td>{{listedCompany.sponsor}}</td></tr>
                <tr><td>律师事务所</td><td>{{listedCompany.law_firm}}</td></tr>
                <tr><td>会计师事务所</td><td>{{listedCompany.Account_firm}}</td></tr>
                <tr><td>时间安排</td><td>{{getYear(listedCompany.formated_schedule)}}</td></tr>
                <tr><td>上市板块</td><td>{{listedCompany.listed_sector}}</td></tr>
                <tr><td>上市状态</td><td>{{listedCompany.list_status}}</td></tr>
                
            </table>
        <div slot="footer">
            <Button type="error"  @click="UnPassed">审核不通过</Button>
            <Button type="primary" @click="passed">审核通过</Button>
            <Button type="ghost"  @click="cancel">关闭页面</Button>
        </div>
    </Modal>
</div>
</template>

<script>
import AutoQuery from "@/common/components/AutoQuery";
import Page from "@/common/model/Page";
import AutoTable from "@/common/components/AutoTable";
import ListedCompany from "@/common/model/ListedCompany";
import CompleteListedCompanyPage from "@/common/components/listed_company_info_page";
import parent from "../Parent";

export default {
    extends:parent,
    components: {
        CompleteListedCompanyPage, AutoTable, AutoQuery
    },
    data() {
        return {
            page: new Page("admin_listed_company/getlist"), //分页查询接口
            query: { // 查询条件
                number:{ type:"input",label:"编号",placeholder:"请输入上市信息编号"},
                title: { type: "input", label: "单位名称：", placeholder: "请输入单位名称" },
                begin_time: { type: "date", label: "上市时间（时间安排）", placeholder: "选择开始时间" },
                end_time: { type: "date", placeholder: "选择截止时间", handleValue: value => { return value + 24*60*60*1000 } },
                listed_sector: { type: "select",label: "上市板块：", placeholder:"请选择上市板块", default: "全部", options: [
                    { value: "全部",label:"全部"},
                    { value: "境外板块",label:"境外板块" },
                    { value: "主板",label:"主板" },
                    { value: "中小板",label:"中小板" },
                    { value: "4创业板",label:"创业板" },
                    { value: "新三板",label:"新三板" },
                    { value: "石交所",label:"石交所" },
                ] },
                list_status: {type: "select",label: "上市状态：",placeholder: "请选择上市状态", default: "全部",  options: [
                    { value: "全部",label:"全部" },
                    { value: "拟上市",label: "拟上市" },
                    { value: "已上市",label: "已上市"}
                ] },
            },
            listedCompany: new ListedCompany(),
            is_modify: false,
            showModal: false,
            checkModal: false,
            columns5: [
                { type: 'index', title:'序号', width: 80, align: 'center' },
                { title: '编号', width: 200, align: 'center', key: 'number' },
                { title: '企业名称', align: 'center', key: 'company_name' },
                { title: '上市状态', align: 'center', key: 'list_status' },
                { title: '板块', align: 'center', key: 'listed_sector' },
                { title: '总股本', align: 'center', key: 'total_equity' },
                { title:"信息状态", align:"center", width:120, render:(h,params) => {
                    return h('div',[
                        h('Button',{
                            props : { type:["warning","success","error"][params.row.status],size:'small' },
                            style : { marginRight: '5px' }
                        },["未审核","审核通过","审核未通过"][params.row.status])
                    ]);
                }},
                { title:"操作", align:"center", key:"action", width:250, render:(h,params) => {
                    return h('div',[
                        h('Button',{
                            props : { type:'success',size:'small' },
                            style : { marginRight: '5px' },
                            on: { click:() => { this.handleCheckDetial(params.row) } },
                        },'查看详情'),
                        h('Button',{
                            props : { type:'error',size:'small', disabled: this.disabledButton("113312") },
                            style : { marginRight: '5px' },
                            on: { click:() => { this.handalDelete(params.row) } },
                        },'删除'),
                        h('Button',{
                            props : { type:'primary',size:'small', disabled: this.disabledButton("113315") },
                            style : { marginRight: '5px' },
                            on: { click:() => {(params.row.status==="1")?this.cancelCheck(params.row):this.checkInfo(params.row) } },
                        }, params.row.status=="1"?"取消审核":"审核")
                    ]);
                }}
            ],
        }
    },
    computed: {
        listedCompanyList() {
            return ListedCompany.parseList(this.page.list);
        }
    },
    methods:{
        handleAdd() {
          this.showModal = true;
          this.is_modify = true;
          this.listedCompany = new ListedCompany();
        },
        handleSubmit() {
            this.$refs["ref1"].validate( valid => {
                if(valid) {
                    var url = this.listedCompany.id ? "admin_listed_company/change" : "admin_listed_company/add";
                    this.api.post(url, { listed_company: this.listedCompany.serialize() }, res=>{
                        if(res.value){
                            this.$CustomMessage.success(res.message);
                            this.page.getData();
                            this.is_modify = true;
                            this.showModal = false;
                        }else{
                            this.$CustomMessage.error(res.message);
                        }
                    });
                }else {
                    
                }
            });
        },
        listenBoard(data)
        {
            if(data==="abroad"){
                this.listedCompany.listed_sector ="";
            }
        },
        handleChange(){
            this.is_modify = true;
        },
        handleCancel() {
            this.showModal = false;
        },
        handleCheckDetial(row) {
            console.log(row);
            this.listedCompany = row;
            this.is_modify = false;
            this.showModal = true;
        },
        handalDelete(row) {
            if(confirm("是否确认删除？不可恢复！")) {
                this.api.post("admin_listed_company/delete", { id: row.id }, res => {
                    if(res.value) {
                        this.$CustomMessage.success(res.message);
                        this.page.getData();
                    }else {
                        this.$CustomMessage.error(res.message)
                    }
                });
            }
        },
        checkInfo(row) {
            this.listedCompany = row;
            this.checkModal = true;
        },
        cancelCheck(row) {
            this.api.post("admin_listed_company/cancel_check",{ id: row.id },res =>{
                if(res.value = true) {
                    this.$CustomMessage.success(res.message);
                    this.page.getData();
                }
                else {
                    this.$CustomMessage.error(res.message);
                }
            });
        },
        UnPassed() {
            this.api.post("admin_listed_company/un_passed",{ id: this.listedCompany.id },res => {
                if(res.value = true) {
                    this.$CustomMessage.success(res.message);
                    this.page.getData();
                }
                else {
                    this.$CustomMessage.error(res.message);
                }
                this.checkModal = false;
            });
        },
        passed() {
            this.api.post("admin_listed_company/passed",{ id: this.listedCompany.id },res => {
                if(res.value = true) {
                    this.$CustomMessage.success(res.message);
                    this.page.getData();
                }
                else {
                    this.$CustomMessage.error(res.message);
                }
                this.checkModal = false;
            });
        },
        cancel() {
            this.checkModal = false;
        },
        getYear(date) {
            return date == null ? "" : date.getFullYear();
        }
    }
}
</script>
<style scoped>
    .sheet p {
        margin: 5px;
    }
    .sheet table {
      font-family: Verdana;
      font-weight: bold;  
      border-width: 1px;    
      width: 870px;
      border-collapse: collapse;
  }
  .sheet table thead th{        
      background-color: rgb(81, 130, 187);
      color: #fff;
      border-bottom-width: 0;
  }
  .sheet table tr {
      border-bottom-width: 0;
  }
  .sheet table td {
      border-right: solid 1px rgb(81, 130, 187);  
  }
  .sheet table tr, .sheet table th {
      border-width: 1px;
      border-style: solid;
      border-color: rgb(81, 130, 187);
  }
  .sheet table td, .sheet table th {
      padding: 5px 10px;
      font-size: 13px;
  }
</style>

